package vrann.dataformats.json;

public class JsonString extends JsonElement
{
	protected String value;
	
	public JsonString() {
		value = "";
	}
	
	public JsonString(String input)
	{
		if (checkString(input)) {
			value = input.replaceAll("\"", "");
		}
	}
	
	public static JsonString initFromString(String input) throws Exception
	{
		if (input.matches("[^\\[\\{\\]\\}]*")) {
			return new JsonString(input.trim());
		} else {
			throw new Exception("String is not valid JSON String");
		}
	}
	
	public String getEscapedString()
	{
		return "\"" + value + "\"";
	}
	
	public String toString()
	{
		return value;
	}
	
	public boolean checkString(String input)
	{
		if (input.matches("[^\\[\\{\\]\\}]*")) {
			return true;
		}
		return false;
	}
}
